home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / op-m-cm.cc < prev    next >
C/C++ Source or Header  |  1997-01-24  |  7KB  |  244 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if defined (__GNUG__)
  24. #pragma implementation
  25. #endif
  26.  
  27. #ifdef HAVE_CONFIG_H
  28. #include <config.h>
  29. #endif
  30.  
  31. #include "gripes.h"
  32. #include "ov.h"
  33. #include "ov-re-mat.h"
  34. #include "ov-cx-mat.h"
  35. #include "ov-typeinfo.h"
  36. #include "op-m-cm.h"
  37. #include "ops.h"
  38. #include "xdiv.h"
  39. #include "xpow.h"
  40.  
  41. // matrix by complex matrix ops.
  42.  
  43. static octave_value
  44. add (const octave_value& a1, const octave_value& a2)
  45. {
  46.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex_matrix&);
  47.  
  48.   return octave_value (v1.matrix_value () + v2.complex_matrix_value ());
  49. }
  50.  
  51. static octave_value
  52. sub (const octave_value& a1, const octave_value& a2)
  53. {
  54.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex_matrix&);
  55.  
  56.   return octave_value (v1.matrix_value () - v2.complex_matrix_value ());
  57. }
  58.  
  59. static octave_value
  60. mul (const octave_value& a1, const octave_value& a2)
  61. {
  62.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex_matrix&);
  63.  
  64.   return octave_value (v1.matrix_value () * v2.complex_matrix_value ());
  65. }
  66.  
  67. static octave_value
  68. div (const octave_value& a1, const octave_value& a2)
  69. {
  70.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex_matrix&);
  71.  
  72.   return xdiv (v1.matrix_value (), v2.complex_matrix_value ());
  73. }
  74.  
  75. static octave_value
  76. pow (const octave_value&, const octave_value&)
  77. {
  78.   error ("can't do A ^ B for A and B both matrices");
  79.   return octave_value ();
  80. }
  81.  
  82. static octave_value
  83. ldiv (const octave_value& a1, const octave_value& a2)
  84. {
  85.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex_matrix&);
  86.  
  87.   return xleftdiv (v1.matrix_value (), v2.complex_matrix_value ());
  88. }
  89.  
  90. #define BOOL_OP(OP, ONE_EMPTY_RESULT, TWO_EMPTY_RESULT) \
  91.   MX_MX_BOOL_OP (Matrix, m1, v1.matrix_value (), \
  92.          ComplexMatrix, m2, v2.complex_matrix_value (), \
  93.          m1 (i, j) OP real (m2 (i, j)), #OP, \
  94.          ONE_EMPTY_RESULT, TWO_EMPTY_RESULT)
  95.  
  96. static octave_value
  97. lt (const octave_value& a1, const octave_value& a2)
  98. {
  99.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex_matrix&);
  100.  
  101.   BOOL_OP (<, Matrix (), Matrix ());
  102. }
  103.  
  104. static octave_value
  105. le (const octave_value& a1, const octave_value& a2)
  106. {
  107.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex_matrix&);
  108.  
  109.   BOOL_OP (<=, Matrix (), Matrix ());
  110. }
  111.  
  112. static octave_value
  113. eq (const octave_value& a1, const octave_value& a2)
  114. {
  115.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex_matrix&);
  116.  
  117.   MX_MX_BOOL_OP (Matrix, m1, v1.matrix_value (),
  118.          ComplexMatrix, m2, v2.complex_matrix_value (),
  119.          m1 (i, j) == m2 (i, j), "==",
  120.          0.0, 1.0);
  121. }
  122.  
  123. static octave_value
  124. ge (const octave_value& a1, const octave_value& a2)
  125. {
  126.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex_matrix&);
  127.  
  128.   BOOL_OP (>=, Matrix (), Matrix ());
  129. }
  130.  
  131. static octave_value
  132. gt (const octave_value& a1, const octave_value& a2)
  133. {
  134.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex_matrix&);
  135.  
  136.   BOOL_OP (>, Matrix (), Matrix ());
  137. }
  138.  
  139. static octave_value
  140. ne (const octave_value& a1, const octave_value& a2)
  141. {
  142.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex_matrix&);
  143.  
  144.   MX_MX_BOOL_OP (Matrix, m1, v1.matrix_value (),
  145.          ComplexMatrix, m2, v2.complex_matrix_value (),
  146.          m1 (i, j) != m2 (i, j), "!=",
  147.          1.0, 0.0);
  148. }
  149.  
  150. static octave_value
  151. el_mul (const octave_value& a1, const octave_value& a2)
  152. {
  153.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex_matrix&);
  154.  
  155.   return product (v1.matrix_value (), v2.complex_matrix_value ());
  156. }
  157.  
  158. static octave_value
  159. el_div (const octave_value& a1, const octave_value& a2)
  160. {
  161.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex_matrix&);
  162.  
  163.   return quotient (v1.matrix_value (), v2.complex_matrix_value ());
  164. }
  165.  
  166. static octave_value
  167. el_pow (const octave_value& a1, const octave_value& a2)
  168. {
  169.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex_matrix&);
  170.  
  171.   return elem_xpow (v1.matrix_value (), v2.complex_matrix_value ());
  172. }
  173.  
  174. static octave_value
  175. el_ldiv (const octave_value& a1, const octave_value& a2)
  176. {
  177.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex_matrix&);
  178.  
  179.   return quotient (v2.complex_matrix_value (), v1.matrix_value ());
  180. }
  181.  
  182. static octave_value
  183. el_and (const octave_value& a1, const octave_value& a2)
  184. {
  185.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex_matrix&);
  186.  
  187.   MX_MX_BOOL_OP (Matrix, m1, v1.matrix_value (),
  188.          ComplexMatrix, m2, v2.complex_matrix_value (),
  189.          m1 (i, j) && m2 (i, j) != 0.0, "&",
  190.          Matrix (), Matrix ());
  191. }
  192.  
  193. static octave_value
  194. el_or (const octave_value& a1, const octave_value& a2)
  195. {
  196.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex_matrix&);
  197.  
  198.   MX_MX_BOOL_OP (Matrix, m1, v1.matrix_value (),
  199.          ComplexMatrix, m2, v2.complex_matrix_value (),
  200.          m1 (i, j) || m2 (i, j) != 0.0, "|",
  201.          Matrix (), Matrix ());
  202. }
  203.  
  204. static octave_value *
  205. complex_matrix_conv (const octave_value& a)
  206. {
  207.   CAST_CONV_ARG (const octave_matrix&);
  208.  
  209.   return new octave_complex_matrix (ComplexMatrix (v.matrix_value ()));
  210. }
  211.  
  212. void
  213. install_m_cm_ops (void)
  214. {
  215.   INSTALL_BINOP (add, octave_matrix, octave_complex_matrix, add);
  216.   INSTALL_BINOP (sub, octave_matrix, octave_complex_matrix, sub);
  217.   INSTALL_BINOP (mul, octave_matrix, octave_complex_matrix, mul);
  218.   INSTALL_BINOP (div, octave_matrix, octave_complex_matrix, div);
  219.   INSTALL_BINOP (pow, octave_matrix, octave_complex_matrix, pow);
  220.   INSTALL_BINOP (ldiv, octave_matrix, octave_complex_matrix, ldiv);
  221.   INSTALL_BINOP (lt, octave_matrix, octave_complex_matrix, lt);
  222.   INSTALL_BINOP (le, octave_matrix, octave_complex_matrix, le);
  223.   INSTALL_BINOP (eq, octave_matrix, octave_complex_matrix, eq);
  224.   INSTALL_BINOP (ge, octave_matrix, octave_complex_matrix, ge);
  225.   INSTALL_BINOP (gt, octave_matrix, octave_complex_matrix, gt);
  226.   INSTALL_BINOP (ne, octave_matrix, octave_complex_matrix, ne);
  227.   INSTALL_BINOP (el_mul, octave_matrix, octave_complex_matrix, el_mul);
  228.   INSTALL_BINOP (el_div, octave_matrix, octave_complex_matrix, el_div);
  229.   INSTALL_BINOP (el_pow, octave_matrix, octave_complex_matrix, el_pow);
  230.   INSTALL_BINOP (el_ldiv, octave_matrix, octave_complex_matrix, el_ldiv);
  231.   INSTALL_BINOP (el_and, octave_matrix, octave_complex_matrix, el_and);
  232.   INSTALL_BINOP (el_or, octave_matrix, octave_complex_matrix, el_or);
  233.  
  234.   INSTALL_ASSIGNCONV (octave_matrix, octave_complex_matrix, octave_complex_matrix);
  235.  
  236.   INSTALL_WIDENOP (octave_matrix, octave_complex_matrix, complex_matrix_conv);
  237. }
  238.  
  239. /*
  240. ;;; Local Variables: ***
  241. ;;; mode: C++ ***
  242. ;;; End: ***
  243. */
  244.